/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ipti.br.tag.entity;

import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author israel
 */
@Entity
public class UnityHolidayCalendar extends AbstractEntity{

    @Column(nullable = false, length = 45)
    private String name;

    @Temporal(TemporalType.DATE)
    @Column(name="holiday_date")
    private Calendar holidayDate;

    @ManyToOne
    @JoinColumn(name = "unity_id")
    private Unity unity;
    
    public UnityHolidayCalendar() {
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String unityHolidayCalendarHashString = "" + this.getName()
                    + this.getHolidayDate()
                    + this.getUnity().getId();
            this.setId(Long.valueOf(EncryptionUtil.encrypt(unityHolidayCalendarHashString).hashCode()));
        }
    }

    public UnityHolidayCalendar(String name, Calendar holidayDate, Unity unity) {
        this.name = name;
        this.holidayDate = holidayDate;
        this.unity = unity;
    }

    public Calendar getHolidayDate() {
        return holidayDate;
    }

    public void setHolidayDate(Calendar holidayDate) {
        this.holidayDate = holidayDate;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Unity getUnity() {
        return unity;
    }

    public void setUnity(Unity unity) {
        this.unity = unity;
    }
}
